/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.full.dialogs;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import br.ufmg.dees.insane.commons.dialogs.DecimalField;
import br.ufmg.dees.insane.commons.dialogs.TabbedDialog;
import br.ufmg.dees.insane.model.ModelState;
import br.ufmg.dees.insane.ui.rich.full.InsaneInternalInterface;
import br.ufmg.dees.insane.ui.rich.full.command.LastZoomCommand;
import br.ufmg.dees.insane.ui.rich.full.command.ZoomAllCommand;

/**
 * A class representing creation dialog on screen.<br>
 * This dialog is provided by some tabs like limits,
 * grid and General settings.<br>
 *
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @see gui.InsaneInternalInterface
 * @since January 2004
 */
public final class StateSettingsDialog extends TabbedDialog {

	private static final long serialVersionUID = 1L;
	private InsaneInternalInterface parent;
    private JPanel generalPane = new JPanel();
    private JPanel limitsPane = new JPanel();
    private JPanel gridPane = new JPanel();
    private JPanel colorsPane = new JPanel();
    private JPanel genPane = new JPanel();
    private JPanel scalesPane = new JPanel();
	private JPanel attributesPane = new JPanel();
	private JPanel diagramsPane = new JPanel();
	private JPanel diaColorsPane = new JPanel();
    
	private double svdX;
	private double svdY;
	private double svdW;
	private double svdH;
	
	private DecimalField xField;
    private DecimalField yField;
    private DecimalField widthField;
    private DecimalField heightField;
    private DecimalField gridwidthField;
    private DecimalField gridheightField;
	
    private DecimalField loadScaleField;
    private DecimalField supportScaleField;
    private DecimalField nodeScaleField;
    private DecimalField deformScaleField;
    private DecimalField diagramScaleField;
    private DecimalField displaceScaleField;
    private DecimalField concForcePointScaleField;
    private DecimalField preStrainsScaleField;
    private DecimalField iniEqForceScaleField;
	private DecimalField reactionsScaleField;
	
	private JTextField gridColorField = new JTextField();
    
	private JTextField backColorField = new JTextField();
    private JTextField pointColorField = new JTextField();
    private JTextField lineColorField = new JTextField();
    private JTextField markColorField = new JTextField();
    private JTextField controlPointColorField = new JTextField();
    private JTextField divisionNodeColorField = new JTextField();
    private JTextField previewLineColorField = new JTextField();
    private JTextField globalAxisColorField = new JTextField();
	private JTextField localAxisColorField = new JTextField();
	private JTextField deformColorField = new JTextField();
	
	private JTextField supportColorField = new JTextField();
    private JTextField loadColorField = new JTextField();
    private JTextField distributedLoadColorField = new JTextField();
	private JTextField springColorField = new JTextField();
    private JTextField concForcePointColorField = new JTextField();
    private JTextField displaceColorField = new JTextField();
    private JTextField preStrainColorField = new JTextField();
    private JTextField iniEqForceColorField = new JTextField();
	private JTextField tempChangeColorField = new JTextField();
	private JTextField reactionsColorField = new JTextField();
	
	private JTextField fxDiagramColorField = new JTextField();
	private JTextField fyDiagramColorField = new JTextField();
	private JTextField fzDiagramColorField = new JTextField();
	private JTextField mxDiagramColorField = new JTextField();
	private JTextField myDiagramColorField = new JTextField();
	private JTextField mzDiagramColorField = new JTextField();
	private JTextField dxDiagramColorField = new JTextField();
	private JTextField dyDiagramColorField = new JTextField();
	private JTextField dzDiagramColorField = new JTextField();
	private JTextField rxDiagramColorField = new JTextField();
	private JTextField ryDiagramColorField = new JTextField();
	private JTextField rzDiagramColorField = new JTextField();
	
private JButton chooseGridColor = new JButton();
	
	private JButton chooseBackColor = new JButton();
    private JButton choosePointColor = new JButton();
    private JButton chooseLineColor = new JButton();
    private JButton chooseMarkColor = new JButton();
    private JButton chooseControlPointColor = new JButton();
    private JButton chooseDivisionNodeColor = new JButton();
    private JButton choosePreviewLineColor = new JButton();
	private JButton chooseGlobalAxisColor = new JButton();
	private JButton chooseLocalAxisColor = new JButton();
	private JButton chooseDeformColor = new JButton();
	
    private JButton chooseSupportColor = new JButton();
    private JButton chooseLoadColor = new JButton();
    private JButton chooseDistributedLoadColor = new JButton();
    private JButton chooseSpringColor = new JButton();
    private JButton chooseConcForcePointColor = new JButton();
    private JButton chooseDisplaceColor = new JButton();
    private JButton choosePreStrainColor = new JButton();
    private JButton chooseIniEqForceColor = new JButton();
	private JButton chooseTempChangeColor = new JButton();
	private JButton chooseReactionsColor = new JButton();
	
	private JButton chooseFxDiagramColor = new JButton();
	private JButton chooseFyDiagramColor = new JButton();
	private JButton chooseFzDiagramColor = new JButton();
	private JButton chooseMxDiagramColor = new JButton();
	private JButton chooseMyDiagramColor = new JButton();
	private JButton chooseMzDiagramColor = new JButton();
	private JButton chooseDxDiagramColor = new JButton();
	private JButton chooseDyDiagramColor = new JButton();
	private JButton chooseDzDiagramColor = new JButton();
	private JButton chooseRxDiagramColor = new JButton();
	private JButton chooseRyDiagramColor = new JButton();
	private JButton chooseRzDiagramColor = new JButton();
    
	private java.awt.geom.Rectangle2D.Double limits = new java.awt.geom.Rectangle2D.Double();
    private String[] precisionStr = {"0", "0.0", "0.00", "0.000", "0.0000", "0.00000", "0.000000", "0.0000000", "0.00000000"};
    private JComboBox precision = new JComboBox(precisionStr);
    private NumberFormat numberFormat;
    private ModelState state;
	
//*****************************************************************************
	
    /**
     * Constructor method, calling super with the especific title.
     *
     * @param parent The parent of the class.
     * @see gui.InsaneInternalInterface
     */
    public StateSettingsDialog(InsaneInternalInterface parent, ModelState s) {
        this.parent = parent;
        state = s;
		
        String chooseStr = parent.getResourceBundle().getString("gChooseButton");
        
        chooseGridColor.setText(chooseStr);
		chooseBackColor.setText(chooseStr);
		choosePointColor.setText(chooseStr);
		chooseLineColor.setText(chooseStr);
		chooseMarkColor.setText(chooseStr);
		chooseControlPointColor.setText(chooseStr);
		chooseDivisionNodeColor.setText(chooseStr);
		choosePreviewLineColor.setText(chooseStr);
		chooseGlobalAxisColor.setText(chooseStr);
		chooseLocalAxisColor.setText(chooseStr);
		chooseDeformColor.setText(chooseStr);
		chooseSupportColor.setText(chooseStr);
		chooseLoadColor.setText(chooseStr);
		chooseDistributedLoadColor.setText(chooseStr);
		chooseSpringColor.setText(chooseStr);
		chooseConcForcePointColor.setText(chooseStr);
		chooseDisplaceColor.setText(chooseStr);
		choosePreStrainColor.setText(chooseStr);
		chooseIniEqForceColor.setText(chooseStr);
		chooseTempChangeColor.setText(chooseStr);
		chooseReactionsColor.setText(chooseStr);
		chooseFxDiagramColor.setText(chooseStr);
		chooseFyDiagramColor.setText(chooseStr);
		chooseFzDiagramColor.setText(chooseStr);
		chooseMxDiagramColor.setText(chooseStr);
		chooseMyDiagramColor.setText(chooseStr);
		chooseMzDiagramColor.setText(chooseStr);
		chooseDxDiagramColor.setText(chooseStr);
		chooseDyDiagramColor.setText(chooseStr);
		chooseDzDiagramColor.setText(chooseStr);
		chooseRxDiagramColor.setText(chooseStr);
		chooseRyDiagramColor.setText(chooseStr);
		chooseRzDiagramColor.setText(chooseStr);
		
		svdX = s.getLimits().x;
		svdY = s.getLimits().y;
		svdW = s.getLimits().width;
		svdH = s.getLimits().height;
		
        setUpFormat();
		
        //Sets fields according to model
        limits.setRect(state.getLimits());
        xField = new DecimalField(limits.x, 10, numberFormat);
        yField = new DecimalField(limits.y, 10, numberFormat);
        widthField  = new DecimalField(limits.width, 10, numberFormat);
        heightField = new DecimalField(limits.height, 10, numberFormat);
        precision.setSelectedIndex(state.getPrecision());
		gridheightField  = new DecimalField(state.getYInc(), 10, numberFormat);
        gridwidthField  = new DecimalField(state.getXInc(), 10, numberFormat);
        loadScaleField  = new DecimalField(state.loadScale, 10, numberFormat);
        supportScaleField = new DecimalField(state.supportScale, 10, numberFormat);
        nodeScaleField = new DecimalField(state.nodeScale, 10, numberFormat);
        deformScaleField = new DecimalField(state.deformScale, 10, numberFormat);
        diagramScaleField = new DecimalField(state.diagramScale, 10, numberFormat);
        displaceScaleField = new DecimalField(state.displaceScale, 10, numberFormat);
        concForcePointScaleField = new DecimalField(state.concForcePointScale, 10, numberFormat);
        preStrainsScaleField = new DecimalField(state.preStrainsScale, 10, numberFormat);
        iniEqForceScaleField = new DecimalField(state.iniEqForceScale, 10, numberFormat);
		reactionsScaleField = new DecimalField(state.reactionsScale, 10, numberFormat);
		
//		 Sets up the limits panel
        JPanel limPane = new JPanel();
        limPane.setLayout(new BoxLayout(limPane, BoxLayout.Y_AXIS));
        limPane.add(limitsPane);
        limitsPane.setLayout(new GridLayout(4,2,2,2));
        limitsPane.setMaximumSize(new Dimension(500,120));
        limitsPane.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder(parent.getResourceBundle().getString("dLimDialog01")),
        BorderFactory.createEmptyBorder(2,2,2,2)));
        limitsPane.add(new JLabel(parent.getResourceBundle().getString("dLimDialog02")));
        limitsPane.add(new JLabel(parent.getResourceBundle().getString("dLimDialog03")));
        limitsPane.add(xField);
        limitsPane.add(yField);
        limitsPane.add(new JLabel(parent.getResourceBundle().getString("dLimDialog04")));
        limitsPane.add(new JLabel(parent.getResourceBundle().getString("dLimDialog05")));
        limitsPane.add(widthField);
        limitsPane.add(heightField);
        
        // Sets up the scales panel
        JPanel scsPane = new JPanel();
        scsPane.setLayout(new BoxLayout(scsPane, BoxLayout.Y_AXIS));
        scsPane.add(scalesPane);
        scalesPane.setLayout(new GridLayout(10,2,2,2));
        scalesPane.setMaximumSize(new Dimension(500,300));
        scalesPane.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder(parent.getResourceBundle().getString("dScaDialog01")),
        BorderFactory.createEmptyBorder(2,2,2,2)));
        scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog02")));
        scalesPane.add(loadScaleField);
        scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog03")));
        scalesPane.add(supportScaleField);
        scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog04")));
        scalesPane.add(nodeScaleField);
        scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog05")));
        scalesPane.add(deformScaleField);
        scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog06")));
        scalesPane.add(diagramScaleField);
		scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog07")));
        scalesPane.add(displaceScaleField);
		scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog08")));
        scalesPane.add(concForcePointScaleField);
		scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog09")));
        scalesPane.add(preStrainsScaleField);
		scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog10")));
        scalesPane.add(iniEqForceScaleField);
		scalesPane.add(new JLabel(parent.getResourceBundle().getString("dScaDialog11")));
        scalesPane.add(reactionsScaleField);
		
        //Sets the colors panel
        colorsPane.setLayout(new GridLayout(10,3,2,2));
        colorsPane.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder(parent.getResourceBundle().getString("dGenSDialog01")),
        BorderFactory.createEmptyBorder(2,2,2,2)));
		colorsPane.setMaximumSize(new Dimension(500,300));
        
		colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog02")));
        backColorField.setEditable(false);
        backColorField.setBackground(state.getBackground());
        colorsPane.add(backColorField);
        colorsPane.add(chooseBackColor);
        chooseBackColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                backColorActionPerformed(e);
            }
        } );
        colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog03")));
        pointColorField.setEditable(false);
        pointColorField.setBackground(state.pointColor);
        colorsPane.add(pointColorField);
        colorsPane.add(choosePointColor);
        choosePointColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                pointColorActionPerformed(e);
            }
        } );
        colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog04")));
        lineColorField.setEditable(false);
        lineColorField.setBackground(state.lineColor);
        colorsPane.add(lineColorField);
        colorsPane.add(chooseLineColor);
        chooseLineColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                lineColorActionPerformed(e);
            }
        } );
        colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog05")));
        markColorField.setEditable(false);
        markColorField.setBackground(state.markColor);
        colorsPane.add(markColorField);
        colorsPane.add(chooseMarkColor);
        chooseMarkColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                markColorActionPerformed(e);
            }
        } );
		colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog06")));
        controlPointColorField.setEditable(false);
        controlPointColorField.setBackground(state.controlPointColor);
        colorsPane.add(controlPointColorField);
        colorsPane.add(chooseControlPointColor);
        chooseControlPointColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                controlPointColorActionPerformed(e);
            }
        } );
		colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog07")));
        divisionNodeColorField.setEditable(false);
        divisionNodeColorField.setBackground(state.divisionNodeColor);
        colorsPane.add(divisionNodeColorField);
        colorsPane.add(chooseDivisionNodeColor);
        chooseDivisionNodeColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                divisionNodeColorActionPerformed(e);
            }
        } );
		colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog08")));
        previewLineColorField.setEditable(false);
        previewLineColorField.setBackground(state.previewElementColor);
        colorsPane.add(previewLineColorField);
        colorsPane.add(choosePreviewLineColor);
        choosePreviewLineColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                previewLineColorActionPerformed(e);
            }
        } );
		colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog09")));
        globalAxisColorField.setEditable(false);
        globalAxisColorField.setBackground(state.globalAxisColor);
        colorsPane.add(globalAxisColorField);
        colorsPane.add(chooseGlobalAxisColor);
        chooseGlobalAxisColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                globalAxisColorActionPerformed(e);
            }
        } );
		colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog10")));
        localAxisColorField.setEditable(false);
        localAxisColorField.setBackground(state.localAxisColor);
        colorsPane.add(localAxisColorField);
        colorsPane.add(chooseLocalAxisColor);
        chooseLocalAxisColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                localAxisColorActionPerformed(e);
            }
        } );
		colorsPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog11")));
        deformColorField.setEditable(false);
        deformColorField.setBackground(state.deformColor);
        colorsPane.add(deformColorField);
        colorsPane.add(chooseDeformColor);
        chooseDeformColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                deformColorActionPerformed(e);
            }
        } );
		
        //Sets internal general panel
        genPane.setLayout(new GridLayout(1,2,2,2));
        genPane.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder(parent.getResourceBundle().getString("dGenSDialog12")),
        BorderFactory.createEmptyBorder(2,2,2,2)));
		genPane.setMaximumSize(new Dimension(500,55));
        genPane.add(new JLabel(parent.getResourceBundle().getString("dGenSDialog12") + ":"));
        genPane.add(precision);
		
        //Sets general panel
        generalPane.setLayout(new BoxLayout(generalPane, BoxLayout.Y_AXIS));
        generalPane.add(genPane);
        generalPane.add(colorsPane);
		
        // Sets up the grid panel
        JPanel gPane = new JPanel();
        gPane.setLayout(new BoxLayout(gPane, BoxLayout.Y_AXIS));
        gPane.add(gridPane);
        gridPane.setLayout(new GridLayout(4,2,2,2));
        gridPane.setMaximumSize(new Dimension(500,120));
        gridPane.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder(parent.getResourceBundle().getString("dGridDialog01")),
        BorderFactory.createEmptyBorder(2,2,2,2)));
        gridPane.add(new JLabel(parent.getResourceBundle().getString("dGridDialog02")));
        gridPane.add(new JLabel(parent.getResourceBundle().getString("dGridDialog03")));
        gridPane.add(gridwidthField);
        gridPane.add(gridheightField);
        gridPane.add(new JLabel(parent.getResourceBundle().getString("dGridDialog04")));
        gridPane.add(new JLabel());
        gridColorField.setEditable(false);
        gridColorField.setBackground(state.gridColor);
        gridPane.add(gridColorField);
        gridPane.add(chooseGridColor);;
        chooseGridColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                gridColorActionPerformed(e);
            }
        } );
		
		//Sets up the attributes panel
		attributesPane.setLayout(new GridLayout(10,3,2,2));
        attributesPane.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder(parent.getResourceBundle().getString("dASDialog01")),
        BorderFactory.createEmptyBorder(2,2,2,2)));
		attributesPane.setMaximumSize(new Dimension(500,300));
        attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog02")));
        supportColorField.setEditable(false);
        supportColorField.setBackground(state.supportColor);
        attributesPane.add(supportColorField);
        attributesPane.add(chooseSupportColor);
        chooseSupportColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                supportColorActionPerformed(e);
            }
        } );
        attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog03")));
        loadColorField.setEditable(false);
        loadColorField.setBackground(state.loadColor);
        attributesPane.add(loadColorField);
        attributesPane.add(chooseLoadColor);
        chooseLoadColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                loadColorActionPerformed(e);
            }
        } );
        attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog04")));
        distributedLoadColorField.setEditable(false);
        distributedLoadColorField.setBackground(state.distributedLoadColor);
        attributesPane.add(distributedLoadColorField);
        attributesPane.add(chooseDistributedLoadColor);
        chooseDistributedLoadColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                distributedLoadColorActionPerformed(e);
            }
        } );
        attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog05")));
        springColorField.setEditable(false);
        springColorField.setBackground(state.springColor);
        attributesPane.add(springColorField);
        attributesPane.add(chooseSpringColor);
        chooseSpringColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                springColorActionPerformed(e);
            }
        } );
		attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog06")));
        concForcePointColorField.setEditable(false);
        concForcePointColorField.setBackground(state.concForcePointColor);
        attributesPane.add(concForcePointColorField);
        attributesPane.add(chooseConcForcePointColor);
        chooseConcForcePointColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                concForcePointColorActionPerformed(e);
            }
        } );
		attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog07")));
        displaceColorField.setEditable(false);
        displaceColorField.setBackground(state.displaceColor);
        attributesPane.add(displaceColorField);
        attributesPane.add(chooseDisplaceColor);
        chooseDisplaceColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                displaceColorActionPerformed(e);
            }
        } );
		attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog08")));
        preStrainColorField.setEditable(false);
        preStrainColorField.setBackground(state.preStrainsColor);
        attributesPane.add(preStrainColorField);
        attributesPane.add(choosePreStrainColor);
        choosePreStrainColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                preStrainColorActionPerformed(e);
            }
        } );
		attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog09")));
        iniEqForceColorField.setEditable(false);
        iniEqForceColorField.setBackground(state.iniEqForceColor);
        attributesPane.add(iniEqForceColorField);
        attributesPane.add(chooseIniEqForceColor);
        chooseIniEqForceColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                iniEqForceColorActionPerformed(e);
            }
        } );
		attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog10")));
        tempChangeColorField.setEditable(false);
        tempChangeColorField.setBackground(state.tempChangeColor);
        attributesPane.add(tempChangeColorField);
        attributesPane.add(chooseTempChangeColor);
        chooseTempChangeColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                tempChangeColorActionPerformed(e);
            }
        } );
		attributesPane.add(new JLabel(parent.getResourceBundle().getString("dASDialog11")));
        reactionsColorField.setEditable(false);
        reactionsColorField.setBackground(state.reactionsColor);
        attributesPane.add(reactionsColorField);
        attributesPane.add(chooseReactionsColor);
        chooseReactionsColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                reactionsColorActionPerformed(e);
            }
        } );
		
		//Sets internal diagrams colors panel
        diaColorsPane.setLayout(new GridLayout(12,3,2,2));
        diaColorsPane.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder(parent.getResourceBundle().getString("dDiaDialog02")),
        BorderFactory.createEmptyBorder(2,2,2,2)));
		diaColorsPane.setMaximumSize(new Dimension(500,400));
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog03")));
        fxDiagramColorField.setEditable(false);
        fxDiagramColorField.setBackground(state.fxDiagramColor);
        diaColorsPane.add(fxDiagramColorField);
        diaColorsPane.add(chooseFxDiagramColor);
        chooseFxDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                fxDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog04")));
        fyDiagramColorField.setEditable(false);
        fyDiagramColorField.setBackground(state.fyDiagramColor);
        diaColorsPane.add(fyDiagramColorField);
        diaColorsPane.add(chooseFyDiagramColor);
        chooseFyDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                fyDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog05")));
        fzDiagramColorField.setEditable(false);
        fzDiagramColorField.setBackground(state.fzDiagramColor);
        diaColorsPane.add(fzDiagramColorField);
        diaColorsPane.add(chooseFzDiagramColor);
        chooseFzDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                fzDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog06")));
        mxDiagramColorField.setEditable(false);
        mxDiagramColorField.setBackground(state.mxDiagramColor);
        diaColorsPane.add(mxDiagramColorField);
        diaColorsPane.add(chooseMxDiagramColor);
        chooseMxDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                mxDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog07")));
        myDiagramColorField.setEditable(false);
        myDiagramColorField.setBackground(state.myDiagramColor);
        diaColorsPane.add(myDiagramColorField);
        diaColorsPane.add(chooseMyDiagramColor);
        chooseMyDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                myDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog08")));
        mzDiagramColorField.setEditable(false);
        mzDiagramColorField.setBackground(state.mzDiagramColor);
        diaColorsPane.add(mzDiagramColorField);
        diaColorsPane.add(chooseMzDiagramColor);
        chooseMzDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                mzDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog09")));
        dxDiagramColorField.setEditable(false);
        dxDiagramColorField.setBackground(state.dxDiagramColor);
        diaColorsPane.add(dxDiagramColorField);
        diaColorsPane.add(chooseDxDiagramColor);
        chooseDxDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dxDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog10")));
        dyDiagramColorField.setEditable(false);
        dyDiagramColorField.setBackground(state.dyDiagramColor);
        diaColorsPane.add(dyDiagramColorField);
        diaColorsPane.add(chooseDyDiagramColor);
        chooseDyDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dyDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog11")));
        dzDiagramColorField.setEditable(false);
        dzDiagramColorField.setBackground(state.dzDiagramColor);
        diaColorsPane.add(dzDiagramColorField);
        diaColorsPane.add(chooseDzDiagramColor);
        chooseDzDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dzDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog12")));
        rxDiagramColorField.setEditable(false);
        rxDiagramColorField.setBackground(state.rxDiagramColor);
        diaColorsPane.add(rxDiagramColorField);
        diaColorsPane.add(chooseRxDiagramColor);
        chooseRxDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                rxDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog13")));
        ryDiagramColorField.setEditable(false);
        ryDiagramColorField.setBackground(state.ryDiagramColor);
        diaColorsPane.add(ryDiagramColorField);
        diaColorsPane.add(chooseRyDiagramColor);
        chooseRyDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ryDiagramColorActionPerformed(e);
            }
        } );
		diaColorsPane.add(new JLabel(parent.getResourceBundle().getString("dDiaDialog14")));
        rzDiagramColorField.setEditable(false);
        rzDiagramColorField.setBackground(state.rzDiagramColor);
        diaColorsPane.add(rzDiagramColorField);
        diaColorsPane.add(chooseRzDiagramColor);
        chooseRzDiagramColor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                rzDiagramColorActionPerformed(e);
            }
        } );
		
		//Sets diagrams panel
        diagramsPane.setLayout(new BoxLayout(diagramsPane, BoxLayout.Y_AXIS));
        diagramsPane.add(diaColorsPane);
		
        addTab(parent.getResourceBundle().getString("dSSDialog01"), generalPane);
        addTab(parent.getResourceBundle().getString("dSSDialog02"), limPane);
        addTab(parent.getResourceBundle().getString("dSSDialog03"), gPane);
        addTab(parent.getResourceBundle().getString("dSSDialog04"), scsPane);
		addTab(parent.getResourceBundle().getString("dSSDialog05"), attributesPane);
		addTab(parent.getResourceBundle().getString("dSSDialog06"), diagramsPane);
        
    }
	
//*****************************************************************************
    
    public int showDialog() {
    	 return super.showDialog(parent, parent.getResourceBundle().getString("dSSDialog07"));
    }
	
//*****************************************************************************
	
    /**
     * This method is executed on OK button click.
     *
     */
    public void approvedPerform() {
        try {
            limits.x = xField.getValue();
            limits.y = yField.getValue();
            limits.height = heightField.getValue();
            limits.width = widthField.getValue();
            
			state.loadScale = loadScaleField.getValue();
            state.supportScale = supportScaleField.getValue();
            state.nodeScale = nodeScaleField.getValue();
            state.deformScale = deformScaleField.getValue();
            state.diagramScale = diagramScaleField.getValue();
            state.displaceScale = displaceScaleField.getValue();
            state.concForcePointScale = concForcePointScaleField.getValue();
            state.preStrainsScale = preStrainsScaleField.getValue();
            state.iniEqForceScale = iniEqForceScaleField.getValue();
			state.reactionsScale = reactionsScaleField.getValue();
			
			state.setXYInc(gridwidthField.getValue(), gridheightField.getValue());
            state.gridColor = gridColorField.getBackground();
            
			state.setBackground(backColorField.getBackground());
            state.pointColor = pointColorField.getBackground();
            state.lineColor = lineColorField.getBackground();
            state.markColor = markColorField.getBackground();
            state.controlPointColor = controlPointColorField.getBackground();
			state.divisionNodeColor = divisionNodeColorField.getBackground();
			state.previewElementColor = previewLineColorField.getBackground();
			state.globalAxisColor = globalAxisColorField.getBackground();
			state.localAxisColor = localAxisColorField.getBackground();
			state.deformColor = deformColorField.getBackground();
			
			state.supportColor = supportColorField.getBackground();
            state.loadColor = loadColorField.getBackground();
            state.distributedLoadColor = distributedLoadColorField.getBackground();
			state.springColor = springColorField.getBackground();
			state.concForcePointColor = concForcePointColorField.getBackground();
			state.displaceColor = displaceColorField.getBackground();
			state.preStrainsColor = preStrainColorField.getBackground();
			state.iniEqForceColor = iniEqForceColorField.getBackground();
			state.tempChangeColor = tempChangeColorField.getBackground();
			state.reactionsColor = reactionsColorField.getBackground();
			
			state.fxDiagramColor = fxDiagramColorField.getBackground();
			state.fyDiagramColor = fyDiagramColorField.getBackground();
			state.fzDiagramColor = fzDiagramColorField.getBackground();
			state.mxDiagramColor = mxDiagramColorField.getBackground();
			state.myDiagramColor = myDiagramColorField.getBackground();
			state.mzDiagramColor = mzDiagramColorField.getBackground();
			state.dxDiagramColor = dxDiagramColorField.getBackground();
			state.dyDiagramColor = dyDiagramColorField.getBackground();
			state.dzDiagramColor = dzDiagramColorField.getBackground();
			state.rxDiagramColor = rxDiagramColorField.getBackground();
			state.ryDiagramColor = ryDiagramColorField.getBackground();
			state.rzDiagramColor = rzDiagramColorField.getBackground();
            
			state.setLimits(limits);
            state.setPrecision(precision.getSelectedIndex());
			
			parent.setModel(parent.getModel());
            this.setVisible(false);
			
			boolean changed = false;
			if (svdX != limits.x) changed = true;
			if (svdY != limits.y) changed = true;
			if (svdW != limits.width) changed = true;
			if (svdH != limits.height) changed = true;
			
			if (changed) {
				ZoomAllCommand cmd = new ZoomAllCommand(parent);
				cmd.execute();
			}
			else {
				LastZoomCommand cmd = new LastZoomCommand(parent);
				cmd.execute();
			}
			
        } catch (Exception err) {
            Toolkit.getDefaultToolkit().beep();
            this.setVisible(false);
        }
    }
    
//*****************************************************************************

    private void gridColorActionPerformed(ActionEvent e) {
        gridColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGridDialog05"), gridColorField.getBackground()));
    }
    
//*****************************************************************************
	
    private void backColorActionPerformed(ActionEvent e) {
        backColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog14"), backColorField.getBackground()));
    }
    
//*****************************************************************************
	
    private void pointColorActionPerformed(ActionEvent e) {
        pointColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog15"), pointColorField.getBackground()));
    }
    
//*****************************************************************************
	
    private void lineColorActionPerformed(ActionEvent e) {
        lineColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog16"), lineColorField.getBackground()));
    }
	
//*****************************************************************************
	
    private void markColorActionPerformed(ActionEvent e) {
        markColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog17"), markColorField.getBackground()));
    }
    
//*****************************************************************************
	
    private void supportColorActionPerformed(ActionEvent e) {
        supportColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog13"), supportColorField.getBackground()));
    }
    
//*****************************************************************************
	
    private void loadColorActionPerformed(ActionEvent e) {
        loadColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog14"), loadColorField.getBackground()));
    }
	
//***************************************************************************
	
  	private void distributedLoadColorActionPerformed(ActionEvent e) {
        distributedLoadColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog15"), distributedLoadColorField.getBackground()));
    }
    
//*****************************************************************************
	
	private void deformColorActionPerformed(ActionEvent e) {
        deformColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog23"), deformColorField.getBackground()));
    }
    
//*****************************************************************************
	
	private void controlPointColorActionPerformed(ActionEvent e) {
		controlPointColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog18"), controlPointColorField.getBackground()));
    }
    
//*****************************************************************************
	
	private void divisionNodeColorActionPerformed(ActionEvent e) {
        divisionNodeColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog19"), divisionNodeColorField.getBackground()));
    }
    
//*****************************************************************************
	
	private void springColorActionPerformed(ActionEvent e) {
        springColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog16"), springColorField.getBackground()));
    }
    
//*****************************************************************************
	
	private void concForcePointColorActionPerformed(ActionEvent e) {
        concForcePointColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog17"), concForcePointColorField.getBackground()));
    }
    
//*****************************************************************************
	
	private void displaceColorActionPerformed(ActionEvent e) {
        displaceColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog18"), displaceColorField.getBackground()));
    }
    
//*****************************************************************************
	
	private void preStrainColorActionPerformed(ActionEvent e) {
        preStrainColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog19"), preStrainColorField.getBackground()));
    }
    
//*****************************************************************************
	
	private void iniEqForceColorActionPerformed(ActionEvent e) {
        iniEqForceColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog20"), iniEqForceColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void previewLineColorActionPerformed(ActionEvent e) {
        previewLineColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog20"), previewLineColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void tempChangeColorActionPerformed(ActionEvent e) {
        tempChangeColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog21"), tempChangeColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void reactionsColorActionPerformed(ActionEvent e) {
        reactionsColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dASDialog22"), reactionsColorField.getBackground()));
    }
	
//*****************************************************************************	
	private void globalAxisColorActionPerformed(ActionEvent e) {
        globalAxisColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog21"), globalAxisColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void localAxisColorActionPerformed(ActionEvent e) {
        localAxisColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dGenSDialog22"), localAxisColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void fxDiagramColorActionPerformed(ActionEvent e) {
        fxDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog15"), fxDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void fyDiagramColorActionPerformed(ActionEvent e) {
        fyDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog16"), fyDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void fzDiagramColorActionPerformed(ActionEvent e) {
        fzDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog17"), fzDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void mxDiagramColorActionPerformed(ActionEvent e) {
        mxDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog18"), mxDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void myDiagramColorActionPerformed(ActionEvent e) {
        myDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog19"), myDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void mzDiagramColorActionPerformed(ActionEvent e) {
        mzDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog20"), mzDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void dxDiagramColorActionPerformed(ActionEvent e) {
        dxDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog21"), dxDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void dyDiagramColorActionPerformed(ActionEvent e) {
        dyDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog22"), dyDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void dzDiagramColorActionPerformed(ActionEvent e) {
        dzDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog23"), dzDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void rxDiagramColorActionPerformed(ActionEvent e) {
        rxDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog24"), rxDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void ryDiagramColorActionPerformed(ActionEvent e) {
        ryDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog25"), ryDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
	private void rzDiagramColorActionPerformed(ActionEvent e) {
        rzDiagramColorField.setBackground(JColorChooser.showDialog(this, parent.getResourceBundle().getString("dDiaDialog26"), rzDiagramColorField.getBackground()));
    }
	
//*****************************************************************************
	
    /**
     * Sets the number formater
     */
    private void setUpFormat() {
        numberFormat = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
        numberFormat.setMaximumFractionDigits(3);
    }
	
//*****************************************************************************
}
